Skip to content

Fix new_window argument typing in Session #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025

Conversation

Data5tream
Copy link
Contributor

@Data5tream Data5tream commented May 21, 2025

Corrects the start_directory type of the new_window method on the Session class.

Fixes #595

Summary by Sourcery

Fix the typing and conditional handling of the start_directory argument in Session.new_window to accept string paths and avoid skipping valid values.

Bug Fixes:

  • Correct start_directory annotation to str | None in Session.new_window
  • Update conditional to if start_directory is not None so empty strings aren’t misinterpreted as absent paths

Copy link

sourcery-ai bot commented May 21, 2025

Reviewer's Guide

This PR fixes the new_window method on the Session class by correcting the start_directory parameter type annotation to str | None and updating the conditional logic to explicitly check for None before expanding and passing the directory argument.

Updated Class Diagram for Session.new_window Method Signature

classDiagram
  class Session {
    +new_window(window_name: str | None, start_directory: str | None, attach: bool, window_index: str, window_shell: str | None, environment: dict[str, str] | None) Window
  }
Loading

File-Level Changes

Change Details Files
Update start_directory parameter type annotation
  • Changed default annotation from None to `str
None`
Refine conditional logic for start_directory
  • Replaced if start_directory with if start_directory is not None to allow empty paths
  • Apply pathlib.Path(...).expanduser() after explicit None check
src/libtmux/session.py

Assessment against linked issues

Issue Objective Addressed Explanation

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@CLAassistant
Copy link

CLAassistant commented May 21, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Data5tream - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@tony tony force-pushed the bugfix/session_new_window_type branch 2 times, most recently from f7e5788 to 09de00a Compare May 26, 2025 09:56
@tony tony self-requested a review May 26, 2025 10:18
Copy link
Member

@tony tony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, good catch!

I will follow up with in https://github.com/tmux-python/libtmux/pull/596/files#r2106995968 in a PR before cutting a new release.

@tony tony merged commit c6445ea into tmux-python:master May 26, 2025
3 of 43 checks passed
tony added a commit that referenced this pull request May 26, 2025
tony added a commit that referenced this pull request May 26, 2025
I'm making mistakes, but follow up to #597, #596

## Summary

This PR adds uniform `StrPath` type support for `start_directory` parameters across all methods in libtmux, enabling PathLike objects (like `pathlib.Path`) to be used alongside strings.

## Changes Made

### Type Annotations Updated
- `Server.new_session`: `start_directory: str | None` → `start_directory: StrPath | None`
- `Session.new_window`: `start_directory: str | None` → `start_directory: StrPath | None`
- `Pane.split` and `Pane.split_window`: `start_directory: str | None` → `start_directory: StrPath | None`
- `Window.split` and `Window.split_window`: `start_directory: str | None` → `start_directory: StrPath | None`

### Implementation Details
- Added `StrPath` import to all affected modules
- Updated docstrings to reflect "str or PathLike" support
- Standardized logic patterns using `if start_directory:` (not `if start_directory is not None:`) to properly handle empty strings
- Added path expansion logic with `pathlib.Path(start_directory).expanduser()` for proper tilde expansion

### Testing
- Added comprehensive parametrized tests for all affected methods
- Test cases cover: `None`, empty string, absolute path string, and `pathlib.Path` objects
- Added separate pathlib-specific tests using temporary directories
- Tests verify operations complete successfully with all input types
- Integrated tests into existing test files following project conventions
@tony
Copy link
Member

tony commented May 26, 2025

@Data5tream Live in v0.46.2 (PyPI, Release, Changelog)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect argument type in the Session class
3 participants